<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\SwtPledge;
use App\Models\SwtMarketChains;
use Dcat\Admin\Form;
use Dcat\Admin\Form\NestedForm;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Card;
use Dcat\Admin\Widgets\Table;

class SwtPledgeController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(SwtPledge::with('coin'), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('coin.base_ccy','币名');
            $grid->column('coin.icon','图标') -> image(config('app.url').'/storage', 50, 50);
            $grid->column('name');
            $grid->column('desc');
            $grid->column('sort')->sortable();
            $grid->column('status') -> using(['禁用','启用']) -> label(['danger', 'success']);
            $grid->column('show_index') -> using(['否','是']) -> label(['danger', 'success']);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->actions(
                function (Grid\Displayers\Actions $actions) {
                    $actions->disableDelete();
                }
            );

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SwtPledge(), function (Show $show) {
            $show->field('id');
            $show->field('coin_id');
            $show->field('name');
            $show->field('desc');
            $show->field('rate');
            $show->field('redeem_rule');
            $show->field('sort');
            $show->field('status');
            $show->field('show_index');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SwtPledge(), function (Form $form) {
            $form -> disableDeleteButton();
            $form -> disableViewButton();
            $form->display('id');
            $form->select('coin_id','币种')
                ->options(SwtMarketChains::where('quote_ccy','USD')->pluck('base_ccy', 'id'))
                ->required()
                ->placeholder('请选择市场链');
            $form->text('name') -> required();
            $form->text('name_for_en') -> required();
            $form->textarea('desc') -> required();
            $form->textarea('desc_for_en') -> required();
            $form->number('sort');
            $form->switch('status');
            $form->switch('show_index');
        });
    }
}
